#ifndef __HANDLE_OPTS_H__
#define __HANDLE_OPTS_H__

#include <stdbool.h>
#include <getopt.h>

#ifdef __cplusplus
extern "C" {
#endif


#define Plog( str , retval )							\
	fprintf(stderr , "%s --FILE:%s LINE:%d\n" , str , __FILE__ , __LINE__ );\
	fflush(stderr);								\
	if( retval ){								\
		exit( retval );							\
	}

typedef enum{
	BOOL,
	INT,
	FLOAT,
	STRING,
} OPTS_TYPE ;

typedef union{
	bool	content_bool;
	int	content_int;
	float	content_float;
	char * 	content_string;
} ALL_TYPE;

typedef struct {
	bool has_selected;
	ALL_TYPE content;
} RET_VALUE_TYPE;

/*
 * type		: Argument type
 * short 	: Short argument option
 * long 	: Long argument option
 * description 	: Despcription of this argument
 * has_arg 	: Is there content following the option
 *
 * ret_value.has_selected : If true, this option is selected default and the ret_value.content is the default value , 
 * 			    or not the default option
 * ret_value.content 	  : It contain the content of this option if it has content when this option appeared in the argument list , 
 * 			    or it contains the default value
 */
typedef struct opts{

	OPTS_TYPE opt_type;

	char short_opt_char;

	char * long_opt_string;
	
	char * instruction;

	bool has_arg;	

	RET_VALUE_TYPE ret_value ;

} OPTS_STRUCT;

int opts_to_string( OPTS_STRUCT* opts_p , unsigned int opt_count , char ** string_p );
int opts_to_options( OPTS_STRUCT * opts_p , unsigned int opt_count , struct option ** option_p_p);
int handle_opts(int argc , char ** argv , OPTS_STRUCT *opts , unsigned int opt_count );
void print_args( OPTS_STRUCT opt );

#ifdef __cplusplus
}
#endif

#endif
